﻿using System;
using System.Collections;
using System.Collections.Generic;

using Wsitech.Model;
using Wsitech.Persistence.Interface;

namespace Wsitech.Persistence.Dao
{
    /// <summary>
    /// 功能：     TextInfo业务接口的实现
    /// 作者：     LI
    /// 日期：     5/16/2012
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class TextInfoSqlMapDao : BaseSqlMapDao, ITextInfoDao
    {
        private TextInfoSqlMapDao()
        {
            //
            // TODO: 此处添加TextInfoSqlMapDao的构造函数
            //
        }

        #region 懒汉单例模式

        private static TextInfoSqlMapDao instance = null;
        private static object syncRoot = new object();
        public static ITextInfoDao Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new TextInfoSqlMapDao();
                        }
                    }
                }
                return instance;
            }
        }

        #endregion

        #region	基本功能 ，不可修改

        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="TextInfoId"></param>
        /// <returns></returns>
        public TextInfo GetDetail(System.String textinfoid)
        {
            try
            {
                return ExecuteQueryForObject<TextInfo>("SelectTextInfo", textinfoid) as TextInfo;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<TextInfo> GetList()
        {
            try
            {
                return ExecuteQueryForList<TextInfo>("SelectTextInfo", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<TextInfo> GetListByParams(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<TextInfo>("SelectTextInfoByParams", objParameters);
            }
            catch
            {
                throw;
            }
        }



        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="textinfo"></param>
        /// <returns></returns>
        public object Add(TextInfo textinfo)
        {
            //int id = GetId("TextInfo");
            //textinfo.TextInfoId = id;

            try
            {
                return ExecuteInsert("InsertTextInfo", textinfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="textinfo"></param>
        /// <returns></returns>
        public int Update(TextInfo textinfo)
        {
            try
            {
                return ExecuteUpdate("UpdateTextInfo", textinfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="TextInfoId"></param>
        /// <returns></returns>
        public int Delete(System.String textinfoid)
        {
            try
            {
                return ExecuteDelete("DeleteTextInfo", textinfoid);
            }
            catch
            {
                throw;
            }
        }
        #endregion

        #region 扩展功能

        #region 获取分页列表

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="ht"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public IList<TextInfo> GetPagedList(Hashtable ht, int pageindex, int pagesize, ref int count)
        {
            count = ExecuteQueryForList("SelectTextInfoByParams", ht).Count;
            int skipResults = (pageindex - 1) * pagesize;
            int maxResults = pagesize;
            return ExecuteQueryForList<TextInfo>("SelectTextInfoByParams", ht, skipResults, maxResults);
        }

        #endregion

        /// <summary>
        ///根据关键字获取相关关视频
        /// </summary>
        /// <param name="ht"></param>
        /// <returns></returns>
        public IList<TextInfo> GetRelatedVideoList(Hashtable ht)
        {
            return ExecuteQueryForList<TextInfo>("GetRelatedVideoList", ht);
        }

        /// <summary>
        /// 根据关键字搜索
        /// </summary>
        /// <param name="htKey"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public IList<TextInfo> GetPagedListByKey(Hashtable htKey, int pageindex, int pagesize, ref int count)
        {
            int skipResults = (pageindex - 1) * pagesize;
            int maxResults = pagesize;
            count = ExecuteQueryForList<TextInfo>("GetListByKey", htKey).Count;
            return ExecuteQueryForList<TextInfo>("GetListByKey", htKey, skipResults, maxResults);
        }

        /// <summary>
        /// 获取上一条或下一条记录
        /// </summary>
        /// <param name="ht"></param>
        /// <returns></returns>
        public TextInfo GetPrevOrNextRecord(Hashtable ht)
        {
            return ExecuteQueryForObject("GetPrevOrNextRecord", ht) as TextInfo;
        }

        #endregion
    }
}
